﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WMM.Tapioca.Linkbase;

namespace WMM.Tapioca.Formula
{
    /// <summary>
    /// Assertion sets serve to define groupings of assertions.
    /// </summary>
    public class AssertionSet : FormulaResource
    {        
        private List<ExistenceAssertion> existenceAssertions;

        /// <summary>
        /// Existence assertion.
        /// </summary>
        public List<ExistenceAssertion> ExistenceAssertions
        {
            get { return existenceAssertions; }
            set { existenceAssertions = value; }
        }
        
        
        private List<ValueAssertion> valueAssertions;

        /// <summary>
        /// Value assertion.
        /// </summary>
        public List<ValueAssertion> ValueAssertions
        {
            get { return valueAssertions; }
            set { valueAssertions = value; }
        }
        
       
        private List<ConsistencyAssertion> consistencyAssertions;

        /// <summary>
        /// Consistency assertion.
        /// </summary>
        public List<ConsistencyAssertion> ConsistencyAssertions
        {
            get { return consistencyAssertions; }
            set { consistencyAssertions = value; }
        }

        public AssertionSet(Resource resourceAssertion, Dictionary<string, string> namespaces)
            : base(resourceAssertion)
        {
            existenceAssertions = new List<ExistenceAssertion>();
            valueAssertions = new List<ValueAssertion>();
            consistencyAssertions = new List<ConsistencyAssertion>();

            foreach (Resource resource in resourceAssertion.ExtendedLinkParent.Resources)
            {
                if (resource.LocalName.Equals("valueAssertion"))
                {
                    valueAssertions.Add(new ValueAssertion(resource, namespaces));
                }

                if (resource.LocalName.Equals("existenceAssertion"))
                {
                    existenceAssertions.Add(new ExistenceAssertion(resource, namespaces));
                }

                if (resource.LocalName.Equals("consistencyAssertion"))
                {
                    consistencyAssertions.Add(new ConsistencyAssertion(resource, namespaces));
                }
            }
        }
        
    }
}
